public class MyQueue {
    static class ListNode{
        public int val;
        public ListNode prev;
        public ListNode next;
        public ListNode(int val){
            this.val=val;
        }
    }
    public ListNode first;
    public ListNode last;
    //采用尾插法
    public void offer(int val){
        ListNode node=new ListNode(val);
        if(first==null){
            first=node;
        }else {
            last.next=node;
            node.prev=last;
        }
        last=node;
    }
    //采用从头删除
    public int poll(){
        if(first==null){
            return -1;
        }
        int val= first.val;
        if(first==last){
            first.val= 0;
            first= null;
            last=null;
        }
        else {
            ListNode cur=first.next;
            cur.prev=null;
            first=cur;
        }
        return val;
    }

    public int peek(){
        if (first==null){
            return -1;
        }
        return first.val;
    }
    public int size(){
     ListNode cur=first;
     int count=0;
     while (cur!=null){
         cur=cur.next;
         count++;
     }
     return count;
    }
    public boolean empty(){
        if(first==null){
            return true;
        }
        return false;
    }

}
